package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:使用匿名内部类继承Thread
 * User: bjc
 * Date: 2025-08-14
 * Time: 20:20
 */
public class ThreadDemo4 {
    public static void main(String[] args) {
        Thread t = new Thread(){
            @Override
            public void run() {
                while (true) {
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        //启动线程
        t.start();
        //main主线程执行的代码
        while (true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
